<?php
/**
 * Created by PhpStorm.
 * User: chenyu
 * Date: 2017-09-11
 * Time: 13:57
 */
defined('DS') or define('DS',DIRECTORY_SEPARATOR);
include(__DIR__.DS.'bootstrap.php');

use EpgApp\modules\sdker\Image\base\ImageCreator,
    EpgApp\modules\sdker\Image\base\ImageException,
    EpgApp\modules\sdker\Image\base\gbclass\ImageSDK,
    EpgApp\modules\sdker\Image\base\gbclass\ImageResource,
    EpgApp\modules\sdker\Image\base\Imagickclass\ImagickSDK;

// $file = __DIR__.DS.'test'.DS.'3.png';

$file = __DIR__.DS.'5.png';
// $image  = \imagecreatefrompng($file);

// var_dump(\getimagesize($image));
// $color = array('red'=>84,'green'=>84,'blue'=>84,'alpha'=>0);
// $color = array('red'=>0,'green'=>0,'blue'=>255,'alpha'=>0);

// var_dump($image);
try{
  $engine  =  new ImageCreator($file,ImageCreator::DBENGIN);
  $creator = $engine->creator() ;
  /**
   * @var ImageSDK $creator
   * **/
//  var_dump($engine,$creator);
 var_dump($creator::getImageInfo(null,'type'),$creator::supportTypes(),$creator::getImageTypeStr());
}catch (ImageException $e)
{
    echo $e->getMessage();
}


$color = array('red'=>203,'green'=>39,'blue'=>38,'alpha'=>0);
$color1 = array('red'=>255,'green'=>0,'blue'=>0,'alpha'=>0); // red
// $index  = \imagecolorexact($creator::getCache('resource'),$color['red'],$color['green'],$color['blue']);
// var_dump($index);

$result =  array();

// $data   = array();
// $data = imagecolorclosest($image,$color['red'],$color['green'],$color['blue']);
// var_dump($data);
/*
for($i=0;$i<$x;$i++)
{
    for($j=0;$j<$y;$j++)
    {
        $tmp = \imagecolorsforindex($image,\imagecolorat($image,$i,$j));
        if(empty($tmp)||!is_array($tmp))
        {
            continue ;
        }
        if($color['red']==$tmp['red']&&$color['green']==$tmp['green']&&$color['blue']==$tmp['blue']&&$color['alpha']==$tmp['alpha'])
        {
            $result[] = array('x'=>$i,'y'=>$j);
            $data[$i][$j] = 1;
        }
    }
}*/
/*
 $bin = __DIR__.DS.'test'.DS.'bin1.txt';
for($j=0;$j<$y;$j++)
{
    $tmp = array();
    for($i=0;$i<$x;$i++)
    {
        if(!empty($data[$i][$j]) && $data[$i][$j]==1)
        {
          $tmp[] = 1;
        }else
        {
                $tmp[] = 0;
        }

    }
    file_put_contents($bin,json_encode($tmp)."\n",FILE_APPEND);
    $tmp = null;
}
// var_dump($data);
 $save = __DIR__.DS.'test'.DS.'red.txt';
 file_put_contents($save, json_encode($result));
*/
